
<template>
        <div class="login-container">
            <div class="box">
            <el-form :model="loginForm" status-icon :rules="rules" ref="loginForm" label-width="100px" class="loginForm">
                <el-form-item class="el-inp" label="用户名" prop="name">
                    <el-input class="input1" v-model="loginForm.name" placeholder="请输入用户名" prefix-icon="el-icon-user"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password"  class="el-inp">
                    <el-input type="password" class="input1" v-model="loginForm.password"  placeholder="请输入密码" autocomplete="off" prefix-icon="el-icon-key"></el-input>
                </el-form-item>
                <el-form-item class="btn">
                    <el-button type="primary" @click="submitForm('loginForm')">登陆</el-button>
                    <el-button @click="resetForm('loginForm')">重置</el-button>
                </el-form-item>
            </el-form>
<!--           <el-button type="primary" @click="T()">测试按钮</el-button>-->
        </div>
        <!--引入粒子特效-->
        <vue-particles
                color="#fff"
                :particleOpacity="0.7"
                :particlesNumber="60"
                shapeType="star"
                :particleSize="4"
                linesColor="#fff"
                :linesWidth="1"
                :lineLinked="true"
                :lineOpacity="0.4"
                :linesDistance="150"
                :moveSpeed="2"
                :hoverEffect="true"
                hoverMode="grab"
                :clickEffect="true"
                clickMode="push"
                class="lizi"
        >
        </vue-particles>

        </div>



</template>


<script>
     import axios from 'axios';
     import server from "@/utils/request";
     import {login} from "@/api/login";
     //缓存this指针
    var that=this;
    export default {
        name:"Login",

        mounted() {
            this.open2();

        },
        data(){

            var checkuserName = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error('用户名不能为空'));
                }
                callback();
            };
            var validatePass = (rule, value, callback) => {
                if (value === '') {
                    callback(new Error('请输入密码'));
                }
                callback();
            };

            return {
                loginForm: {
                    password: '',
                    name: ''
                },
                rules: {
                    password: [
                        { validator: validatePass, trigger: 'blur' }
                    ],

                   name: [
                        { validator: checkuserName, trigger: 'blur' }
                    ]
                }
            };
        },
        methods: {
            submitForm(formName) {
                const _this = this;
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        // axios.request({
                        //     method:'psot',
                        //     url:'http://localhost:8080/user/login',
                        //     params:this.loginForm
                        // })
                        // server.post('http://localhost:8080/user/login',this.loginForm).then(res=>{
                        //     const userInfo = res.data.data;
                        //     if(userInfo.success=true){
                        //         _this.$router.push("/layout");
                        //     }
                        // });
                        login(this.loginForm).then(res=>{
                            const userInfo = res.data.data;
                            if(userInfo.success=true){
                                _this.$router.push("/layout");
                            }
                        });

                    } else {

                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            },
            T() {
                axios.get('https://v1.hitokoto.cn')
                    .then(({ data }) => {
                        const hitokoto = data.hitokoto;
                        console.log(hitokoto);
                        alert(hitokoto);
                    })
                    .catch(console.error)
            } ,
            open2() {
                const _this = this;
                this.$notify({
                    title: '提示',
                    dangerouslyUseHTMLString: true,
                    message: '<div style="color: teal"> <strong>欢迎进入博客后台管理系统。还没有账号？👉 <router-link to="/register">马上注册</strong></div>',
            //         h('div', null, [
            //             h('span', { style: 'color: teal' }, '还没有账号？👉 '),
            //         h('router-link', {to: '/register',style: 'color: teal'},'马上注册'),
            // ])
                    // h('div',null,'还没有账号？  <router-link to="/register">马上注册 👉</router-link>ss')this.$router.push("/home");
                    type: 'info',
                    onClick: function() {
                        console.log('点我干啥');
                        _this.$router.push("/register");
                    }
                });

            },

        }


    }

</script>



<style scoped>

    .login-container{
        width: 100%;
        height: 100%;
        /*background-color: #2c3e50;*/
        background-image: url("../../assets/bgimg.jpg");
        background-size: 100% 100%;
        background-repeat: no-repeat;
        position: fixed;
    }
    .box {
        width: 400px;
        height: 290px;
        /*background: #e5e9f2;*/
        position: absolute;
        left: 50%;
        top: 50%;
        margin-left: -220px;
        margin-top: -170px;
        border-radius: 5px;
        padding-top: 40px;
        padding-right: 40px;
        /*透明*/
        /*opacity:0.5;*/
        /*filter:alpha(opacity=50);*/
    }
    .login-container .box .el-inp .input1{
        border: red;
        opacity:0.5;
        filter:alpha(opacity=50);
    }




</style>